package cn.sm1234.service.impl;

import cn.sm1234.dao.CustomerMapper;
import cn.sm1234.domain.Customer;
import cn.sm1234.service.CustomerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

// 服务实现要在当前目录之下
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
    // 注入mapper接口的对象
    @Resource
    private CustomerMapper customerMapper;


    @Override
    public void save(Customer customer) {
        if (customer.getId() != null){
            customerMapper.update(customer);
        }else{
            customerMapper.save(customer);
        }
    }

    @Override
    public List<Customer> findAll() {
        return customerMapper.findAll();
    }

    @Override
    public Customer findById(Integer id) {
        return customerMapper.findById(id);
    }

    @Override
    public void delete(Integer id) {
        customerMapper.delete(id);
    }
}

